
<%@ page language="java" %>

<%@ page import="com.scalar.chiptrack.utils.ConfigManager,
                 com.scalar.chiptrack.operations.reports.WipFlush,
                 java.util.ArrayList,
                 java.util.HashMap,
                 java.util.Iterator,
                 com.scalar.chiptrack.utils.StringUtils,
                 com.scalar.chiptrack.operations.reports.forms.WipFlushForm"%>

<%@ taglib uri="/WEB-INF/chiptrack-tags.tld" prefix="chiptrack" %>


<HTML><HEAD><TITLE>Scalarsoft - ChipTrac</TITLE>

<%String chipTracContext = "/" + ConfigManager.getChipTracContext();%>

<META http-equiv=Content-Type content="text/html; charset=windows-1252">
<LINK href="<%=chipTracContext%>/jsp/includes/stylesheets/scalarsoft.css" type=text/css rel=stylesheet>

<style>
<!--
.HEADING     { cursor: hand; font-family: Verdana,Arial,San Serif; font-size: 12px; color: #000000;
               background-color: #FFFFFFF; font-weight: none;
               border: 1 solid #000000 }
-->
</style>

<Script Language="javascript">

function call(rowName,rowSize,stage){
    var pa=document.getElementById("errors");
    pa.innerHTML = "";

    if (stage == 'root') {
        var status = checkSubChilds(rowName,rowSize)
    }

	for(i=0;i< rowSize;i++){

        var obj = eval("document.all."+rowName+i);

		if(obj.style.display == "none"){
			obj.style.display = "block";
		}else{
            if (status == "OPEN")
            {
                pa.innerHTML = "<li> Please close the branches hierarchically.";
            }
            else
			{obj.style.display = "none";}
		}
	}
}

function checkSubChilds(rowName,rowSize){
    var localStatus = 'CLOSE';

    for(i=0; i < rowSize; i++){
        var obj = eval("document.all."+rowName+i+"lot0");

        if (obj != null)
        {
            if(obj.style.display == "block"){
			    localStatus = 'OPEN';
		    }
        }
	}

    return localStatus;
}
function printView( )
{
    var url = '<%=chipTracContext%>/jsp/operations/wip_flush_by_product_print_view.jsp?heading=<%=(String) request.getAttribute("heading")%>&holdHeading=<%=(String) request.getAttribute( "holdHeading" )%>';
    newWindow = window.open ( url,'printerFriendlyPopup','channelmode=no,directories=no,toolbar=no,menubar=no,personalbar=no,status=no,scrollbars=yes,width=800,height=550,resizable=yes');
}
function exportToFile( )
{
    var url = '<%=chipTracContext%>/wipFlushExportToFile.do?reportType=byProduct&heading=<%=(String) request.getAttribute("heading")%>&holdHeading=<%=(String) request.getAttribute( "holdHeading" )%>&vendorExpand=<%=(String) request.getAttribute( "vendorExpand" )%>&lotExpand=<%=(String) request.getAttribute( "lotExpand" )%>';
    newWindow = window.open ( url,'printerFriendlyPopup','channelmode=no,directories=no,toolbar=no,menubar=no,personalbar=no,status=no,scrollbars=yes,width=450,height=150,resizable=yes');
}

</Script>


<META content="MSHTML 5.50.4807.2300" name=GENERATOR></HEAD>
<BODY bgColor="#ffffff" leftMargin=0 topMargin=0 marginheight="0" marginwidth="0">

<!-- Top Header Start-->
<%@include file="/jsp/includes/header.jsp"  %>
<!-- Top Header End-->

<TABLE cellSpacing=0 cellPadding=0 width="100%" border=0>
  <TBODY>
  <TR>
	<TD width='180' valign='top' background='<%=chipTracContext%>/jsp/includes/images/left_red_bg.gif'>
        <!-- Side Navigation start -->
        <%@ include file="/jsp/operations/reports_side_menu.jsp" %>
        <!-- end of the side navigations -->
    </TD>

   <TD bgcolor="#ffffff">
        <IMG height=9 src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" width=8>
   </TD>
   <TD bgcolor="#ffffff">
        <IMG height=480 src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" width=2>
   </TD>

<TD valign="top" width="100%">

<IMG height=1 src="<%=chipTracContext%>/jsp/includes/images/clear.gif" width=500 border=0>


<!-- Start : Wip Flush Report -->

<TABLE width="100%" border="0">
    <TBODY>

    <TR>
    		<TD valign="top" bgcolor="#ffffff" >&nbsp;
				<IMG height=9 src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" width="8">
            </TD>
			<TD valign="top" >
                <IMG  src="<%=chipTracContext%>/jsp/includes/images/clear.gif" width="500" height="1" border="0">
                <!-- Start : Report Block -->

                <%
                    String heading = (String) request.getAttribute("heading");
                    String holdHeading = (String) request.getAttribute( "holdHeading" );
                %>

				<table valign="top" width="95%" border="0">
                    <tr>
						<td colspan = "12" valign="top"><center><span class="NArialW">Wip Flush - <%=heading%> Report By Product <%=holdHeading%></span></center></td>
					</tr>
                    <tr>
                        <%
                            WipFlushForm wipFlushForm = ( WipFlushForm )request.getAttribute( "wipFlushForm" );
                            ArrayList baseProductList = (ArrayList) session.getAttribute ("wipFlush");
                            if ( baseProductList != null && baseProductList.size() > 0)
                            {
                        %>
						        <td colspan = "12" valign="top" CLASS="NArialL"><CENTER><A HREF="javascript:printView()">[Printer-Friendly]</A>
                                                        &nbsp;&nbsp;<A HREF="javascript:exportToFile()">[Export To File]</A></CENTER></td>
                        <%
                            }
                        %>
					</tr>

                    <tr>
						<td colspan = "12" valign="top" class='NArialS'><FONT styleClass="NArialS" color="blue"><img border="0" src="<%=chipTracContext%>/jsp/includes/images/exclamation-46x47.gif"  WIDTH="20" HEIGHT="20"/>[Click on bars to Expand or Collapse the List]</FONT></td>
					</tr>

                    <tr>
						<td colspan = "12" valign="top" class='NArialL'><FONT id="errors" styleClass="NArialL" color="#FF0000"></FONT></td>
					</tr>

                    <%
                        String wipFlushInfo = "";

                        String vendorExpand = (String) request.getAttribute("vendorExpand");
                        String lotExpand = (String) request.getAttribute("lotExpand");

                        if ( baseProductList == null || baseProductList.size() == 0) {
                                wipFlushInfo = "<font color='red'>No information found </font>";
                                out.println ("<tr><td colspan = '12'><font class='NArialL' color='#FF0000'><li>" + wipFlushInfo + "</font></td></tr>");
                        }
                        else
                        {
                     %>

					<tr>
						<td colspan="12" valign="top">&nbsp;</td>
					</tr>

					<tr bgcolor="#993333" align = "center">
						<td width="9%" nowrap><font class='NArialL'><font color="#FFFFFF">Part Number</font></font></td>
						<td width="9%" nowrap><font class='NArialL'><font color="#FFFFFF">Vendor Name</font></font></td>
						<td width="9%" nowrap><font class='NArialL'><font color="#FFFFFF">Lot No#</font></font></td>
						<td width="9%"><font class='NArialL'><font color="#FFFFFF">Fab</font></font></td>
                        <td width="9%"><font class='NArialL'><font color="#FFFFFF">Wafer Store</font></font></td>
                        <td width="9%"><font class='NArialL'><font color="#FFFFFF">Sort</font></font></td>
                        <td width="9%"><font class='NArialL'><font color="#FFFFFF">DieBank</font></font></td>
                        <td width="9%"><font class='NArialL'><font color="#FFFFFF">Assembly</font></font></td>
                        <td width="9%"><font class='NArialL'><font color="#FFFFFF">Test</font></font></td>
						<!--<td width="9%"><font class='NArialL'><font color="#FFFFFF">FPO</font></font></td>
                        <td width="9%"><font class='NArialL'><font color="#FFFFFF">Class Store</font></font></td>-->
						<td width="9%"><font class='NArialL'><font color="#FFFFFF">Finished Goods</font></font></td>
				    </tr>
                     <%

                                WipFlush baseproduct = null;
		                        WipFlush product = null;
		                        WipFlush vendor = null;
		                        WipFlush lot = null;

		                        HashMap childProducts = null;
		                        Iterator it = null;
		                        HashMap vendorMap = null;
		                        Iterator vendorIt = null;

		                        HashMap lotMap = null;
		                        Iterator lotIt = null;

                                String partNumber = "";
                                String vendorName = "";

                                int partCount = 0;
                                int vendorCount = 0;
                                int lotCount = 0;

                                int fabTotalQty = 0;
                                int waferStoreTotalQty = 0;
                                int fabOptionTotalQty = 0;
                                int sortTotalQty = 0;
                                int dieBankTotalQty = 0;
                                int assemblyTotalQty = 0;
                                int testTotalQty = 0;
                                int ftTotalQty = 0;
                                int fpoTotalQty = 0;
                                int classStoreTotalQty = 0;
                                int fgTotalQty = 0;

                                for( int i = 0; i < baseProductList.size(); i++ )
			                    {
                                    baseproduct = (WipFlush)baseProductList.get(i);

                                    if (baseproduct != null)
                                    {

                                        out.print("<tr bgcolor='#F2DBDB'>");
						                out.print("<td width='9%' align='left'><font class='NArialL'>&nbsp;&nbsp;&nbsp;&nbsp;"+ baseproduct.getPartNumber() +"</font></td>");
						                out.print("<td width='9%' ><font class='NArialL'></font></td>");
						                out.print("<td width='9%' ><font class='NArialL'></font></td>");
						                out.print("<td width='9%' align='right'><font class='NArialL'>"+ baseproduct.getFormattedFabQty() +"</font></td>");
                                        out.print("<td width='9%' align='right'><font class='NArialL'>"+ baseproduct.getFormattedWaferStoreQty() +"</font></td>");
                                        out.print("<td width='9%' align='right'><font class='NArialL'>"+ baseproduct.getFormattedSortQty() +"</font></td>");
                                        out.print("<td width='9%' align='right'><font class='NArialL'>"+ baseproduct.getFormattedDieBankQty() +"</font></td>");
                                        out.print("<td width='9%' align='right'><font class='NArialL'>"+ baseproduct.getFormattedAssemblyQty() +"</font></td>");
						                out.print("<td width='9%' align='right'><font class='NArialL'>"+ baseproduct.getFormattedTestQty() +"</font></td>");
                                        /*out.print("<td width='9%' align='right'><font class='NArialL'>"+ baseproduct.getFormattedFpoQty() +"</font></td>");
                                        out.print("<td width='9%' align='right'><font class='NArialL'>"+ baseproduct.getFormattedClassStoreQty() +"</font></td>");*/
						                out.print("<td width='9%' align='right'><font class='NArialL'>"+ baseproduct.getFormattedFgQty() +"</font></td>");
				                        out.print("</tr>");
                                    }

                                    childProducts = baseproduct.getChildMap();
				                    if( childProducts != null )
				                    {
                                        it = childProducts.keySet().iterator();
					                    while( it.hasNext() )
					                    {
                                            vendorCount = 0;
                                            partNumber = "part"+partCount;
                                            product = (WipFlush)childProducts.get( it.next() );

                                            vendorMap = product.getChildMap();
                    %>

                    <%
                        if(vendorMap == null || vendorMap.size()==0)
                        {
                    %>
                    <tr bgcolor="#CDCEE9">
                    <td width="9%" align = "left" nowrap><font class='NArialL'>&nbsp;&nbsp;&nbsp;&nbsp;<%=product.getPartNumber()%></font></td>
                    <%
                        }
                        else
                        {
                    %>
                    <tr bgcolor="#CDCEE9" onclick="call('<%=partNumber%>vendor','<%=vendorMap.size()%>','root')" CLASS="HEADING">
                    <td width="9%" align = "left" nowrap><font class='NArialL'><IMG src="<%=chipTracContext%>/jsp/includes/images/bullet2.GIF" width="12" height="12">&nbsp;<%=product.getPartNumber()%></font></td>
                    <%
                        }
                        fabTotalQty += product.getFabQty() ;
                        waferStoreTotalQty += product.getWaferStoreQty();
                        /*fabOptionTotalQty += product.getFabOptionQty();*/
                        sortTotalQty += product.getSortQty();
                        dieBankTotalQty += product.getDieBankQty();
                        assemblyTotalQty += product.getAssemblyQty();
                        testTotalQty += product.getTestQty();
                        /*ftTotalQty += product.getFtQty();
                        fpoTotalQty += product.getFpoQty();
                        classStoreTotalQty += product.getClassStoreQty();*/
                        fgTotalQty += product.getFgQty();
                    %>
						<td width="9%" align = "left"><font class='NArialL'>&nbsp;</font></td>
						<td width="9%" align = "left"><font class='NArialL'>&nbsp;</font></td>
						<td width="9%" align = "right"><font class='NArialL'><%=product.getFormattedFabQty()%></font></td>
                        <td width="9%" align = "right"><font class='NArialL'><%=product.getFormattedWaferStoreQty()%></font></td>
                        <td width="9%" align = "right"><font class='NArialL'><%=product.getFormattedSortQty()%></font></td>
                        <td width="9%" align = "right"><font class='NArialL'><%=product.getFormattedDieBankQty()%></font></td>
                        <td width="9%" align = "right"><font class='NArialL'><%=product.getFormattedAssemblyQty()%></font></td>
						<td width="9%" align = "right"><font class='NArialL'><%=product.getFormattedTestQty()%></font></td>
						<%--<td width="9%" align = "right"><font class='NArialL'><%=product.getFormattedFpoQty()%></font></td>
                        <td width="9%" align = "right"><font class='NArialL'><%=product.getFormattedClassStoreQty()%></font></td>--%>
                        <td width="9%" align = "right"><font class='NArialL'><%=product.getFormattedFgQty()%></font></td>
					</tr>

                    <%
                        if( vendorMap != null )
						{
                            vendorIt = vendorMap.keySet().iterator();
							while( vendorIt.hasNext() )
							{
                                lotCount = 0;
                                vendorName = "vendor"+vendorCount;
								vendor = (WipFlush)vendorMap.get( vendorIt.next() );
                                lotMap = vendor.getChildMap();

                   %>

                    <%
                        if(lotMap == null || lotMap.size()==0)
                        {
                    %>
                    <tr bgcolor="#DEE1E2" id="<%=partNumber%>vendor<%=vendorCount%>" style="<%=vendorExpand%>" >
   						<td width="9%" align = "left"><font class='NArialL'>&nbsp;</font></td>
						<td width="9%" align = "left" nowrap><font class='NArialL'>&nbsp;&nbsp;&nbsp;&nbsp;<%=vendor.getVendor()%></font></td>
                    <%
                        }
                        else
                        {

                    %>
                    <tr bgcolor="#DEE1E2" id="<%=partNumber%>vendor<%=vendorCount%>" style="<%=vendorExpand%>" onclick="call('<%=partNumber%><%=vendorName%>lot','<%=lotMap.size()%>','sub')" CLASS="HEADING">
                        <td width="9%" align = "left"><font class='NArialL'>&nbsp;</font></td>
						<td width="9%" align = "left" nowrap><font class='NArialL'><IMG src="<%=chipTracContext%>/jsp/includes/images/bullet2.GIF" width="12" height="12">&nbsp;<%=vendor.getVendor()%></font></td>
                    <%
                        }
                    %>
						<td width="9%" align = "left"><font class='NArialL'>&nbsp;</font></td>
						<td width="9%" align = "right"><font class='NArialL'><%=vendor.getFormattedFabQty()%></font></td>
                        <td width="9%" align = "right"><font class='NArialL'><%=vendor.getFormattedWaferStoreQty()%></font></td>
                        <td width="9%" align = "right"><font class='NArialL'><%=vendor.getFormattedSortQty()%></font></td>
                        <td width="9%" align = "right"><font class='NArialL'><%=vendor.getFormattedDieBankQty()%></font></td>
                        <td width="9%" align = "right"><font class='NArialL'><%=vendor.getFormattedAssemblyQty()%></font></td>
						<td width="9%" align = "right"><font class='NArialL'><%=vendor.getFormattedTestQty()%></font></td>
						<%--<td width="9%" align = "right"><font class='NArialL'><%=vendor.getFormattedFpoQty()%></font></td>
                        <td width="9%" align = "right"><font class='NArialL'><%=vendor.getFormattedClassStoreQty()%></font></td>--%>
                        <td width="9%" align = "right"><font class='NArialL'><%=vendor.getFormattedFgQty()%></font></td>
					</tr>

                   <%
                                if( lotMap != null && lotMap.isEmpty() == false )
								{
									lotIt = lotMap.keySet().iterator();
									while( lotIt.hasNext() )
									{
										lot = (WipFlush)lotMap.get( lotIt.next() );
                   %>

                   <%
                       if (lot != null)
                       {

                   %>
                   <tr bgcolor="#DEE1E2" id="<%=partNumber%><%=vendorName%>lot<%=lotCount%>" style="<%=lotExpand%>">
						<td width="9%"  align = "left"><font class='NArialL'>&nbsp;</font></td>
						<td width="9%"  align = "left"><font class='NArialL'>&nbsp;</font></td>
						<td width="9%"  align = "left" nowrap><font class='NArialL'>&nbsp;<%=lot.getLotNumber()%></font></td>
						<td width="9%" align = "right"><font class='NArialL'><%=lot.getFormattedFabQty()%></font></td>
                        <td width="9%" align = "right"><font class='NArialL'><%=lot.getFormattedWaferStoreQty()%></font></td>
                        <td width="9%" align = "right"><font class='NArialL'><%=lot.getFormattedSortQty()%></font></td>
                        <td width="9%" align = "right"><font class='NArialL'><%=lot.getFormattedDieBankQty()%></font></td>
                        <td width="9%" align = "right"><font class='NArialL'><%=lot.getFormattedAssemblyQty()%></font></td>
						<td width="9%" align = "right"><font class='NArialL'><%=lot.getFormattedTestQty()%></font></td>
						<%--<td width="9%" align = "right"><font class='NArialL'><%=lot.getFormattedFpoQty()%></font></td>
                        <td width="9%" align = "right"><font class='NArialL'><%=lot.getFormattedClassStoreQty()%></font></td>--%>
                        <td width="9%" align = "right"><font class='NArialL'><%=lot.getFormattedFgQty()%></font></td>
					</tr>
                    <% } %>

                   <%
                                                        lotCount++;
                                                        } // End of lot looping
                                                    } // End of lot != null condition
                                                vendorCount++;
                                                } // End og vendors looping
                                            } // End of vendorIt != null condition
                                            partCount++;
                                         } // End of child products looping
                                    } // End of child products  != null condition
                                } // End of baseProduct looping
                    %>

                    <tr bgcolor="#993333">
						<td width="9%" align="left"><font class='NArialL'><font color="#FFFFFF">&nbsp;&nbsp;&nbsp;&nbsp;Grand Total</font></font></td>
						<td width="9%"><font class='NArialL'><font color="#FFFFFF">&nbsp;</font></font></td>
						<td width="9%"><font class='NArialL'><font color="#FFFFFF">&nbsp;</font></font></td>
						<td width="9%" align="right"><font class='NArialL'><font color="#FFFFFF"><%=StringUtils.getUSNumberFormat(fabTotalQty)%></font></font></td>
                        <td width="9%" align="right"><font class='NArialL'><font color="#FFFFFF"><%=StringUtils.getUSNumberFormat(waferStoreTotalQty)%></font></font></td>
                        <td width="9%" align="right"><font class='NArialL'><font color="#FFFFFF"><%=StringUtils.getUSNumberFormat(sortTotalQty)%></font></font></td>
                        <td width="9%" align="right"><font class='NArialL'><font color="#FFFFFF"><%=StringUtils.getUSNumberFormat(dieBankTotalQty)%></font></font></td>
                        <td width="9%" align="right"><font class='NArialL'><font color="#FFFFFF"><%=StringUtils.getUSNumberFormat(assemblyTotalQty)%></font></font></td>
						<td width="9%" align="right"><font class='NArialL'><font color="#FFFFFF"><%=StringUtils.getUSNumberFormat(testTotalQty)%></font></font></td>
						<%--<td width="9%" align="right"><font class='NArialL'><font color="#FFFFFF"><%=StringUtils.getUSNumberFormat(fpoTotalQty)%></font></font></td>
						<td width="9%" align="right"><font class='NArialL'><font color="#FFFFFF"><%=StringUtils.getUSNumberFormat(classStoreTotalQty)%></font></font></td>--%>
						<td width="9%" align="right"><font class='NArialL'><font color="#FFFFFF"><%=StringUtils.getUSNumberFormat(fgTotalQty)%></font></font></td>
				    </tr>

                    <%
                        }
                        // End of wipFlush != null condition
                    %>

				</table>
                <!-- End : Report Block -->

			<BR><BR><BR>
		    </TD>
		</TR>
    </TBODY>
</TABLE>
<!-- End : Wip Flush Report -->


<BR><BR><BR>
</TD>

<TD bgcolor="#ffffff"><IMG height=1 src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" width=1></TD>
</TR>
</TABLE>

<!-- Footer starts here -->
<%@include file="/jsp/includes/footer.jsp" %>
<!-- footer end here -->

</BODY>
</HTML>
